{% extends "pretixpresale/organizers/base.html" %}
{% load i18n %}
{% load rich_text %}
{% load tz %}
{% load eventurl %}
{% load urlreplace %}
{% load thumb %}
{% block title %}{% trans "Event list" %}{% endblock %}
{% block custom_header %}
    {{ block.super }}
    <meta property="og:title" content="{{ organizer.name }}"/>
    {% if organizer_logo %}
        <meta property="og:image" content="{{ organizer_logo|thumb:'5000x120' }}"/>
    {% endif %}
    <meta property="og:type" content="website"/>
    <meta property="og:url" content="{% abseventurl organizer "presale:organizer.index" %}"/>
{% endblock %}
{% block content %}
    <div>
        {% if organizer_homepage_text %}
            {{ organizer_homepage_text | rich_text }}
        {% endif %}
    </div>
    {% if "old" in request.GET %}
        <h3>{% trans "Past events" %}</h3>
    {% else %}
        <h3>{% trans "Upcoming events" %}</h3>
    {% endif %}
    <div>
        <div class="btn-group" role="group">
            <a href="?{% url_replace request "style" "list" "week" "" "year" "" "month" "" %}" type="button"
                    class="btn btn-default active">
                <span class="fa fa-list" aria-hidden="true"></span>
                {% trans "List" %}
            </a>
            <a href="?{% url_replace request "style" "week" "month" "" "old" "" "page" "" %}" type="button"
                    class="btn btn-default">
                <span class="fa fa-calendar" aria-hidden="true"></span>
                {% trans "Week" %}
            </a>
            <a href="?{% url_replace request "style" "calendar" "week" "" "old" "" "page" "" %}" type="button"
                    class="btn btn-default">
                <span class="fa fa-calendar" aria-hidden="true"></span>
                {% trans "Month" %}
            </a>
        </div>
        <a href="{% eventurl request.organizer "presale:organizer.ical" %}?{% url_replace request "locale" request.LANGUAGE_CODE "page" "" "old" "" "week" "" "style" "" "month" "" "year" "" %}"
                class="btn btn-default">
            <span class="fa fa-calendar-plus-o" aria-hidden="true"></span>
            {% trans "iCal" %}
        </a>
        {% if "old" in request.GET %}
            <a href="?{% url_replace request "old" "" %}" class="btn btn-link">{% trans "Show upcoming" %}</a>
        {% else %}
            <a href="?{% url_replace request "old" "1" %}" class="btn btn-link">{% trans "Show past events" %}</a>
        {% endif %}
    </div>
    <div class="event-list">
        <div class="row hidden-xs hidden-sm">
            <div class="col-md-5">
                <strong>{% trans "Name" %}</strong>
            </div>
            <div class="col-md-3">
                <strong>{% trans "Date" %}</strong>
            </div>
            <div class="col-md-2">
                <strong>{% trans "Status" %}</strong>
            </div>
            <div class="col-md-2">
            </div>
        </div>
        {% for e in events %}{% eventurl e "presale:event.index" as url %}
            <div class="row">
                <div class="col-md-5 col-xs-12">
                    <a href="{{ url }}">
                        <strong>
                            {{ e.name }}
                        </strong>
                    </a>
                </div>
                <div class="col-md-3 col-xs-12">

                    {% if e.settings.show_dates_on_frontpage %}
                        {{ e.daterange|default:e.get_date_range_display }}
                        {% if e.settings.show_times and not e.has_subevents %}
                            {% timezone e.tzname %}
                                <br><small class="text-muted" data-time="{{ e.date_from.isoformat }}" data-timezone="{{ e.tzname }}">
                                {{ e.date_from|date:"TIME_FORMAT" }}
                                {% if e.settings.show_date_to and e.date_to and e.date_to.date == e.date_from.date %}
                                    – {{ e.date_to|date:"TIME_FORMAT" }}
                                {% endif %}
                            </small>
                            {% endtimezone %}
                        {% endif %}
                    {% else %}
                        &nbsp;
                    {% endif %}
                    <td>
                </div>
                <div class="col-md-2 col-xs-6">
                    {% if e.has_subevents %}
                        <span class="label label-default">{% trans "Event series" %}</span>
                    {% elif e.presale_is_running and request.organizer.settings.event_list_availability %}
                        {% if e.best_availability_state == 100 %}
                            <span class="label label-success">{% trans "Book now" %}</span>
                        {% elif e.settings.waiting_list_enabled and e.best_availability_state >= 0 %}
                            <span class="label label-warning">{% trans "Waiting list" %}</span>
                        {% elif e.best_availability_state == 20 %}
                            <span class="label label-warning">{% trans "Reserved" %}</span>
                        {% elif e.best_availability_state < 20 %}
                            {% if e.has_paid_item %}
                                <span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Sold out" %}
                            {% else %}
                                <span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Fully booked" %}
                            {% endif %}
                        {% endif %}
                    {% elif e.presale_is_running %}
                        <span class="label label-success">{% trans "Book now" %}</span>
                    {% elif e.presale_has_ended %}
                        <span class="label label-danger">{% trans "Sale over" %}</span>
                    {% elif e.settings.presale_start_show_date %}
                        <span class="label label-warning">
                                {% blocktrans trimmed with date=e.effective_presale_start|date:"SHORT_DATE_FORMAT" %}
                                    Sale starts {{ date }}
                                {% endblocktrans %}
                            </span>
                    {% else %}
                        <span class="label label-warning">{% trans "Not yet on sale" %}</span>
                    {% endif %}
                </div>
                <div class="col-md-2 col-xs-6 text-right flip">
                    <a class="btn btn-primary btn-block" href="{{ url }}">
                        {% if e.has_subevents %}<span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Tickets" %}
                        {% elif e.presale_is_running and e.best_availability_state == 100 %}
                            <span class="fa fa-ticket" aria-hidden="true"></span> {% trans "Tickets" %}
                        {% else %}
                            <span class="fa fa-info" aria-hidden="true"></span> {% trans "More info" %}
                        {% endif %}
                    </a>
                </div>
            </div>
        {% empty %}
            {% if "old" in request.GET %}
                <div class="col-md-12">
                    <em>{% trans "No archived events found." %}</em>
                </div>
            {% else %}
                <div class="col-md-12">
                    <em>{% trans "No public upcoming events found." %}</em>
                </div>
            {% endif %}
        {% endfor %}
    </div>
    {% include "pretixpresale/pagination.html" %}
{% endblock %}
